import { createRouter, createWebHashHistory, RouteRecordRaw } from 'vue-router'
const Layout = () => import('@/layout/index.vue')

const routes: Array<RouteRecordRaw> = [
  {
    path: '/',
    component: Layout,
    children: [
      {
        path: '/',
        name: 'Index',
        component: () => import('@/views/index/index.vue'),
        meta: {
          title: '健康GangGang',
          keepAlive: true
        }
      },
      {
        path: '/remind',
        name: 'Remind',
        component: () => import('@/views/remind/index.vue'),
        meta: {
          title: '设置提醒',
          keepAlive: false
        }
      },
      {
        path: '/recordCompletion',
        name: 'RecordCompletion',
        component: () => import('@/views/recordCompletion/index.vue'),
        meta: {
          title: '打卡',
          keepAlive: false
        }
      }
    ]
  }
]

const router = createRouter({
  history: createWebHashHistory(),
  routes
})

router.beforeEach((to, _, next) => {
  document.title = to.meta.title as string
  next()
})

export default router
